Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Jun 16, 2025

as title.

PMS-BUG-314371

Summary by Sourcery

Add system opacity support to X11 window previews by subscribing to the Deepin appearance DBus interface and redrawing the preview background with the current opacity.

New Features:

  • Retrieve system window opacity from org.deepin.dde.Appearance1 via DBus.
  • Listen for opacity change signals and update preview transparency dynamically.
  • Implement custom paintEvent to draw rounded preview backgrounds using the system opacity value.

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

Integrates window preview rendering with the system’s configured opacity by connecting to the Appearance1 D-Bus interface, dynamically fetching updates, and overriding paintEvent to draw a rounded background using the current opacity and theme.

Sequence Diagram for Opacity Initialization on Startup

sequenceDiagram
    participant X11WPC as X11WindowPreviewContainer
    participant QDBusI as QDBusInterface
    participant AppearanceService as org.deepin.dde.Appearance1

    X11WPC->>X11WPC: constructor()
    activate X11WPC
    X11WPC->>QDBusI: new QDBusInterface("org.deepin.dde.Appearance1", ...)
    QDBusI-->>X11WPC: m_appearanceInterface
    X11WPC->>X11WPC: connect(m_appearanceInterface, Changed, onSystemOpacityChanged)
    X11WPC->>X11WPC: getSystemOpacity()
    activate X11WPC #LightBlue
    X11WPC->>QDBusI: m_appearanceInterface.property("Opacity")
    activate QDBusI
    QDBusI->>AppearanceService: GetProperty("Opacity")
    activate AppearanceService
    AppearanceService-->>QDBusI: opacityValue
    deactivate AppearanceService
    QDBusI-->>X11WPC: opacityVariant
    deactivate QDBusI
    X11WPC->>X11WPC: m_systemOpacity = opacityVariant.toReal()
    deactivate X11WPC #LightBlue
    deactivate X11WPC
Loading

Sequence Diagram for Handling System Opacity Change

sequenceDiagram
    participant AppearanceService as org.deepin.dde.Appearance1
    participant QDBusI as QDBusInterface
    participant X11WPC as X11WindowPreviewContainer

    AppearanceService->>QDBusI: Signal: Changed("windowopacity", ...)
    activate QDBusI
    QDBusI->>X11WPC: onSystemOpacityChanged("windowopacity", ...)
    deactivate QDBusI
    activate X11WPC
    X11WPC->>X11WPC: getSystemOpacity()
    activate X11WPC #LightBlue
    X11WPC->>QDBusI: m_appearanceInterface.property("Opacity")
    activate QDBusI
    QDBusI->>AppearanceService: GetProperty("Opacity")
    activate AppearanceService
    AppearanceService-->>QDBusI: newOpacityValue
    deactivate AppearanceService
    QDBusI-->>X11WPC: newOpacityVariant
    deactivate QDBusI
    X11WPC->>X11WPC: m_systemOpacity = newOpacityVariant.toReal()
    X11WPC->>X11WPC: update() /* Triggers repaint */
    deactivate X11WPC #LightBlue
    deactivate X11WPC
Loading

Sequence Diagram for Custom Window Preview Painting

sequenceDiagram
    participant QtFramework
    participant X11WPC as X11WindowPreviewContainer
    participant Painter as QPainter
    participant DGuiHelper as DGuiApplicationHelper
    participant DStyleH as DStyleHelper

    QtFramework->>X11WPC: paintEvent(event)
    activate X11WPC
    X11WPC->>Painter: new QPainter(this)
    Painter-->>X11WPC: painter
    X11WPC->>DGuiHelper: DGuiApplicationHelper::instance()->themeType()
    activate DGuiHelper
    DGuiHelper-->>X11WPC: themeType
    deactivate DGuiHelper
    X11WPC->>X11WPC: Calculate backgroundColor (using m_systemOpacity, themeType)
    X11WPC->>DStyleH: new DStyleHelper(style())
    activate DStyleH
    DStyleH-->>X11WPC: dstyle
    deactivate DStyleH
    X11WPC->>DStyleH: dstyle.pixelMetric(DStyle::PM_FrameRadius)
    activate DStyleH
    DStyleH-->>X11WPC: radius
    deactivate DStyleH
    X11WPC->>Painter: painter.drawRoundedRect(rect(), radius, radius)
    deactivate X11WPC
Loading

Updated Class Diagram for X11WindowPreviewContainer

classDiagram
    class X11WindowPreviewContainer {
        +QDBusInterface* m_appearanceInterface
        +double m_systemOpacity
        +paintEvent(QPaintEvent* event) void
        #getSystemOpacity() double
        #onSystemOpacityChanged(const QString& propertyName, const QString& value) void
    }
    DBlurEffectWidget <|-- X11WindowPreviewContainer
Loading

File-Level Changes

Change Details Files
Integrated with D-Bus Appearance interface to fetch and listen for system opacity settings
  • Added QDBusInterface include and m_appearanceInterface member
  • Initialized m_appearanceInterface in constructor and connected Changed signal
  • Fetched initial opacity into m_systemOpacity on instantiation
panels/dock/taskmanager/x11preview.cpp
panels/dock/taskmanager/x11preview.h
Implemented methods to retrieve and handle system opacity changes
  • Added getSystemOpacity() to query the D-Bus Opacity property with a fallback value
  • Added onSystemOpacityChanged slot to update m_systemOpacity and call update() when 'windowopacity' changes
panels/dock/taskmanager/x11preview.cpp
panels/dock/taskmanager/x11preview.h
Overrode paintEvent to render a rounded-rectangle background with dynamic opacity
  • Implemented paintEvent using QPainter with antialiasing and theme-based color selection
  • Used DStyleHelper to obtain frame radius and draw a rounded rect filled with alpha based on m_systemOpacity
panels/dock/taskmanager/x11preview.cpp
panels/dock/taskmanager/x11preview.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @wjyrich - I've reviewed your changes - here's some feedback:

  • Verify that the D-Bus signal name and property casing in onSystemOpacityChanged match the Appearance1 interface (e.g. "Opacity" vs "windowopacity") so you reliably update opacity.
  • Consider using QDBusReply or QDBusPendingCall to fetch the Appearance1 property instead of QDBusInterface::property for clearer error handling and asynchronous support.
  • To avoid reallocating style helpers each frame, cache the corner-radius (DStyle::PM_FrameRadius) outside paintEvent rather than recreating DStyleHelper on every paint.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Verify that the D-Bus signal name and property casing in onSystemOpacityChanged match the Appearance1 interface (e.g. "Opacity" vs "windowopacity") so you reliably update opacity.
- Consider using QDBusReply or QDBusPendingCall to fetch the Appearance1 property instead of QDBusInterface::property for clearer error handling and asynchronous support.
- To avoid reallocating style helpers each frame, cache the corner-radius (DStyle::PM_FrameRadius) outside paintEvent rather than recreating DStyleHelper on every paint.

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/x11preview.cpp:799` </location>
<code_context>
+    if (m_appearanceInterface && m_appearanceInterface->isValid()) {
+        QVariant opacityVariant = m_appearanceInterface->property("Opacity");
+        if (opacityVariant.isValid()) {
+            double opacity = opacityVariant.toReal();
+            return opacity;
+        }
</code_context>

<issue_to_address>
Clamp opacity value to [0, 1]

The D-Bus property may return values outside the expected range. Use qBound(0.0, opacity, 1.0) to ensure opacity stays within [0, 1] before using it.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
double X11WindowPreviewContainer::getSystemOpacity()
{
    if (m_appearanceInterface && m_appearanceInterface->isValid()) {
        QVariant opacityVariant = m_appearanceInterface->property("Opacity");
        if (opacityVariant.isValid()) {
            double opacity = opacityVariant.toReal();
            return opacity;
        }
=======
#include <QtGlobal>

double X11WindowPreviewContainer::getSystemOpacity()
{
    if (m_appearanceInterface && m_appearanceInterface->isValid()) {
        QVariant opacityVariant = m_appearanceInterface->property("Opacity");
        if (opacityVariant.isValid()) {
            double opacity = opacityVariant.toReal();
            opacity = qBound(0.0, opacity, 1.0);
            return opacity;
        }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wjyrich wjyrich force-pushed the fix-bug-314371 branch 3 times, most recently from 6c4cc21 to a9d2cf9 Compare June 16, 2025 09:16
@wjyrich wjyrich force-pushed the fix-bug-314371 branch 7 times, most recently from fdd1961 to de61cc2 Compare June 17, 2025 03:35
@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • modifyOpacityChanged 函数中重复创建了 DAppletBridgeappearanceApplet 对象,应该将其提取为成员变量以避免重复创建。
  • modifyOpacityChanged 函数中缺少对 opacity 的范围检查,可能会导致 setMaskAlpha 接受无效的透明度值。
  • setPreviewOpacity 函数中直接修改了 m_opacity 变量,但没有同步更新相关的 UI 元素,可能会导致显示不一致。
  • setPreviewOpacity 函数中的 m_opacity 变量应该有默认值,以防止未初始化的指针访问。

是否建议立即修改:

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-bot
Copy link

deepin-bot bot commented Jun 19, 2025

TAG Bot

New tag: 2.0.0
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1166

@deepin-bot
Copy link

deepin-bot bot commented Jun 24, 2025

TAG Bot

New tag: 2.0.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1169

@wjyrich
Copy link
Contributor Author

wjyrich commented Jun 27, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jun 27, 2025

This pr force merged! (status: unknown)

@deepin-bot deepin-bot bot merged commit 9abb8fd into linuxdeepin:master Jun 27, 2025
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants